//
//  UIBarButtonItem+Extensions.swift
//  SwiftWeibo
//
//  Created by Lausen on 2017/4/8.
//  Copyright © 2017年 id. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    /// 自定义UIBarButtonItem的方法
    ///
    /// - Parameters:
    ///   - title: item的title
    ///   - fontSize: 字体大小
    ///   - target: 监听者
    ///   - action: 执行的方法
    ///   - isBack: 是否是返回按钮
    convenience init(title: String,fontSize: CGFloat = 16,target: Any?,action: Selector,isBack: Bool = false) {
        
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack {
        
            let norImage = UIImage(named: "navigationbar_back_withtext")
            btn.setImage(norImage, for: .normal)
            
            let higIamge = UIImage(named: "navigationbar_back_withtext_highlighted")
            btn.setImage(higIamge, for: .highlighted)
            
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        //遍历构造 函数本身不会实例化对象,需要调用self.init()的构造函数
        self.init(customView: btn)
    }
}
